package com.atguigu.security.bean;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * @program: springboot-05-security
 * @description:
 * @author: qiaoli
 * @create: 2020-04-28 09:51
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User implements UserDetails {

    @TableId(type = IdType.AUTO)
    private  int uid;
    private  String phone;
    private  String password;
    private  String name;
    private List<Role> roles;
    @JsonIgnore
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return roles;
    }
   //@JsonIgnore 让此属性不在进行json化
   @JsonIgnore
    @Override
    public String getUsername() {
        return phone;
    }
    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }
    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }
    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }
    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return true;
    }
}
